package com.nail.soulda.person;

import java.util.Random;
import java.util.StringTokenizer;

import com.nail.soulda.FileStruct;

public abstract class IPerson {
	protected String name;
	protected int sex;
	protected long blood;
	protected long attack;
	protected long defence;
	
	public IPerson() {
		
	}
	
	public IPerson(String _name, int type) {
		/* initial all data */
		this.name = _name;
		this.sex = type;
		/* need initial other property in derived class */		
	}
	
	@Override
	public String toString() {
		return (this.name + FileStruct.TOKEN + this.sex + FileStruct.TOKEN + this.blood + FileStruct.TOKEN + 
				this.attack + FileStruct.TOKEN + this.defence + "\n");
	}
	
	public void setData(String data) {
		StringTokenizer t = new StringTokenizer(data, FileStruct.TOKEN);	    
	    this.name = t.nextToken();
	    this.sex = Integer.parseInt(t.nextToken());
	    this.blood = Long.parseLong(t.nextToken());
	    this.attack = Long.parseLong(t.nextToken());
	    this.defence = Long.parseLong(t.nextToken());
	}
	
	public void showInfo() {
		System.out.println("==============" + this.name + " Info==============");
		System.out.println("= sex: " + (this.sex == FileStruct.Sex.male ? "mail" : "femail"));
		System.out.println("= blood: " + this.blood);
		System.out.println("= attack: " + this.attack);
		System.out.println("= defence: " + this.defence);
		System.out.println("=====================================");		
	}
	
	public long attack() {
		return this.attack;
	}
	
	public long defence() {
		return this.defence;
	}
	
	public long loseBlood(long value) {
		this.blood = this.blood - value;
		return this.blood;
	}
	
	public String getName() {
		return this.name;
	}
	
}
